home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / TWEENER / TWEN / COMTWEN.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.3 KB  |  166 lines

  1. /* $Id: COMTwen.cpp 1.4 1997/04/05 02:39:04 damien Exp $ */
  2.  
  3. ////////////////////////////////////////////////////////////////////////
  4. //   Tweener Example : ?????                                          //
  5. //--------------------------------------------------------------------//
  6. //   Implementation of the Tweener Interface                          //
  7. //////////////////////////////////////////////////////////////////////// 
  8.  
  9.  
  10. #ifndef __COMTWEN__
  11. #include "COMTWEN.h"
  12. #endif
  13.  
  14. #ifndef __TWENDLL__
  15. #include "TWENDLL.h"
  16. #endif
  17.  
  18. #ifndef __3DCOFAIL__
  19. #include "3DCoFail.h"
  20. #endif
  21.  
  22. #include "Math.h"
  23. #ifndef M_PI
  24. #define M_PI 3.141592657
  25. #endif
  26.  
  27.  
  28. #undef INTERFACE
  29. #define INTERFACE Tweener
  30. // Constructor / Destructor of the C++ Object :
  31. Tweener::Tweener() {
  32.   fCRef=0; // Reference Counter
  33.   // Data initialisation :
  34.   fData.fNbOsc = 5;
  35.   fData.fExpCoef = 1.0;
  36.   fExpCoef = 1.0;
  37.   fCosCoef = 2* (fData.fNbOsc+0.25) * M_PI;
  38.   }
  39.   
  40. Tweener::~Tweener() {
  41.   global_count_Obj--; 
  42.   }
  43.   
  44. // IUnknown Interface :
  45. HRESULT Tweener::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
  46.   *ppvObj=NULL;
  47.   
  48.   // The Tweener knows the interfaces of the parent Objects
  49.   if (IsEqualIID(riid, IID_IUnknown))
  50.     *ppvObj=(LPVOID)this;
  51.   else if (IsEqualIID(riid, IID_I3DExTweener))
  52.     *ppvObj=(LPVOID)this;
  53.   else if (IsEqualIID(riid, IID_I3DExDataExchanger))
  54.     *ppvObj=(LPVOID)this;
  55.   else if (IsEqualIID(riid, IID_I3DExtension))
  56.     *ppvObj=(LPVOID)this;
  57.     
  58.   // we must add reference if we return an interface
  59.   if (*ppvObj!=NULL) {
  60.     ((LPUNKNOWN)*ppvObj)->AddRef();
  61.     return NOERROR;
  62.     }
  63.   else {
  64.     return ResultFromScode(E_NOINTERFACE);
  65.     }
  66.   }
  67.  
  68. ULONG Tweener::AddRef(THIS) {
  69.   return fCRef++;
  70.   }
  71.   
  72. ULONG Tweener::Release(THIS) {
  73.   ULONG UnreleaseObject=fCRef--;
  74.   
  75.   if (fCRef==0)
  76.      delete this; // No reference left, so destroy the object
  77.   
  78.   return UnreleaseObject;
  79.   // local variable used, because fCRef can be destroyed before.
  80.   }
  81.   
  82. // I3DExtension methods :
  83. I3DExtension* Tweener::Clone(THIS) {
  84.   Tweener* theClone = new Tweener;
  85.   if (theClone) {
  86.     theClone->AddRef();
  87.     theClone->fData=fData; // copy the TweenerData
  88.     theClone->fCosCoef=fCosCoef;
  89.     theClone->fExpCoef=fCosCoef;
  90.     }                               
  91.   return theClone;
  92.   }   
  93.  
  94. HRESULT Tweener::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
  95.   InitCoFailure(shellUtilities);
  96.   return NOERROR;
  97.   }
  98.  
  99. // I3DExDataExchanger methods :
  100. ExtensionDataMap* Tweener::GetExtensionDataMap(THIS) {
  101.   return NULL;
  102.   }
  103.  
  104. void* Tweener::GetExtensionDataBuffer(THIS) {
  105.   return &fData; // used by the shell to set the new parameters
  106.   }
  107.   
  108. HRESULT Tweener::ExtensionDataChanged(THIS) {
  109.   fCosCoef = 2*M_PI*(fData.fNbOsc+0.25);
  110.   fExpCoef=(double)fData.fExpCoef;
  111.   return NOERROR;
  112.   }
  113.  
  114. HRESULT Tweener::HandleEvent(THIS_ ULONG SourceID) {
  115.   return ResultFromScode(E_NOTIMPL);
  116.   }
  117.  
  118. short Tweener::GetResID(THIS) {
  119.   return 144; // this is the view ID in the resource file.
  120.   }
  121.   
  122. HRESULT Tweener::DoTweening(THIS_ NUM3D& lambda,long time,long time1, long time2) {
  123.   long delta = time2 - time1;
  124.   float t,value;
  125.   if (delta==0) {
  126.     lambda=0;
  127.     return NOERROR;
  128.     }
  129.   t = (1.0*time - time1) / delta;
  130.  
  131.   value = (1-cos(t*fCosCoef)*exp(-t*fExpCoef));
  132.  
  133.   lambda = (double)value;
  134.  
  135.   return NOERROR;
  136.   }
  137.     
  138. HRESULT Tweener::DoTween (THIS_ IShKeyFrame *res,long time,XTweenerChainLink *alink) {
  139.     return ResultFromScode(E_NOTIMPL);
  140.     }
  141.     
  142. HRESULT Tweener::Draw (THIS_ IShGraphicDevice *aGD,const LRect *area,const LRect *where) {
  143.     return ResultFromScode(E_NOTIMPL);
  144.     }
  145.     
  146. HRESULT Tweener::DoValue (THIS_ NUM3D &res,long time,XTweenerChainLink *alink,I3DShTreeElement *tree) {
  147.     return ResultFromScode(E_NOTIMPL);
  148.     }
  149.     
  150. HRESULT Tweener::DoVector2 (THIS_ VECTOR2D &res,long time,XTweenerChainLink *alink,I3DShTreeElement *tree) {
  151.     return ResultFromScode(E_NOTIMPL);
  152.     }
  153.     
  154. HRESULT Tweener::DoVector3 (THIS_ VECTOR3D &res,long time,XTweenerChainLink *alink,I3DShTreeElement *tree) {
  155.     return ResultFromScode(E_NOTIMPL);
  156.     }
  157.     
  158. HRESULT Tweener::DoColor (THIS_ COLOR3D &res,long time,XTweenerChainLink *alink,I3DShTreeElement *tree) {
  159.     return ResultFromScode(E_NOTIMPL);
  160.     }
  161.     
  162. HRESULT Tweener::DoRotation (THIS_ MATRIX3D &res,long time,XTweenerChainLink *alink,I3DShTreeElement *tree) {
  163.     return ResultFromScode(E_NOTIMPL);
  164.     }
  165.     
  166.